{
	template:`
	<a-page-header title="主机列表">
		<template #extra>
			<div style="padding-top:7px;">
				<a-checkbox v-model:checked="timeRefresh" @change="toTimeRefresh">定时刷新(10s)</a-checkbox>
			</div>
		</template>
		<a-row :gutter="[10,10]">
		    <a-col v-for="item in list" :xs="24" :sm="24" :xl="24" :xxl="12">
                <a-card :hoverable="true" :bodyStyle="{padding:0,margin:'-1px'}">
					<template #title>
						<m-icon :name="item.oid=='0'?'icon-logistic':'icon-online-tracking'" size="18" :color="item.ipport==host.ipport?'var(--colorPrimary)':''"/>
						{{item.oid}}:{{item.osInfo}} <span class="text-blue">{{item.ipport}}</span>
						<span class="text-gray">-</span> {{item.serverName}}
						<small v-if="item.serverMain=='Y'">（主）</small>
					</template>
                    <template #extra>
                        <a-space>
                            <a-button v-if="item.serverName==host.serverName" type="primary" @click="viewCache(item)">查看缓存</a-button>
                            <a-dropdown>
                                <a-button danger>操控</a-button>
                                <template #overlay>
                                <a-menu>
                                    <a-menu-item v-if="item.jarName">
                                        <a-typography-text type="danger" @click="toOperHost(item)">重启</a-typography-text>
                                    </a-menu-item>
                                    <a-menu-item>
                                        <a-typography-text type="danger" @click="stopHost(item.ipport)">停止</a-typography-text>
                                    </a-menu-item>
                                    <a-popover title="升级文件" @openChange="loadJarList" placement="leftBottom">
                                        <a-menu-item v-if="item.jarName">
                                            <a-typography-text type="danger">选择升级</a-typography-text>
                                        </a-menu-item>
                                        <template #content>
                                        <a-spin :spinning="isLoadJarList">
                                        <div style="width:400px;margin:-10px;">
                                            <a-list size="small">
                                                <a-list-item v-for="im in jarList" key="im.oid">
                                                    <a-list-item-meta :title="im.name">
                                                    </a-list-item-meta>
                                                    <template #extra>
                                                        <a-button v-if="im.name!=item.jarName" type="link" @click="toOperHost(item,im)" danger>确认升级</a-button>
                                                    </template>
                                                </a-list-item>
                                            </a-list>
                                        </div>
                                        </a-spin>
                                        </template>
                                    </a-popover>
                                </a-menu>
                                </template>
                            </a-dropdown>
                        </a-space>
                    </template>
                    <a-descriptions bordered size="small" :column="2">
                        <a-descriptions-item label="web端口">{{item.serverPort}}</a-descriptions-item>
                        <a-descriptions-item label="服务时间">{{new Date(item.createDate).formatShow('yyyy-MM-dd HH:mm:ss')}} ~{{new Date(item.lastDate).formatShow('yyyy-MM-dd HH:mm:ss')}}</a-descriptions-item>
                        <a-descriptions-item label="DB链接">{{item.dbUseLinkNum}} / {{item.dbMaxLinkNum}}</a-descriptions-item>
                        <a-descriptions-item label="JVM内存">{{item.freeMemory}}M / {{item.totalMemory}}M / {{item.maxMemory}}M</a-descriptions-item>
                        <a-descriptions-item v-if="item.error" label="错误"><a-typography-text type="danger">{{item.error}}</a-typography-text></a-descriptions-item>
                    </a-descriptions>
                </a-card>
		    </a-col>
		</a-row>
	</a-page-header>
	<a-modal v-model:open="operModal" width="400px" :closable="false" :keyboard="false" :mask-closable="false" class="index-modal">
        <a-page-header title="重启" :sub-title="operHost.ipport">
		    <a-card :hoverable="true" :bodyStyle="{padding:'20px 20px 0'}">
                <a-form class="index-form" :wrapper-col="{span:24}">
                    <a-row :gutter="10">
                        <a-col v-if="operJar&&operJar.oid" :span="24">
                            <a-form-item label="升级文件" class="index-form-item">
                                {{operJar.name}}
                            </a-form-item>
                        </a-col>
                        <a-col :span="24">
                            <a-form-item label="初始Java堆" class="index-form-item">
                                <a-input-number v-model:value="operParam.xms" :formatter="value => value+'m'" :parser="value => value.replace('m', '')"/>
                            </a-form-item>
                        </a-col>
                        <a-col :span="24">
                            <a-form-item label="最大Java堆" class="index-form-item">
                                <a-input-number v-model:value="operParam.xmx" :formatter="value => value+'m'" :parser="value => value.replace('m', '')"/>
                            </a-form-item>
                        </a-col>
                        <a-col :span="24">
                            <a-form-item label="启动参数" class="index-form-item">
                                <span v-if="operParam.xms"> -Xms{{operParam.xms}}m</span>
                                <span v-if="operParam.xmx"> -Xmx{{operParam.xmx}}m</span>
                            </a-form-item>
                        </a-col>
		            </a-row>
		        </a-form>
		    </a-card>
		    <div style="padding-top:15px;text-align:right;">
		        <a-popconfirm title="确定要重启吗？" @confirm="doOperHost">
		            <a-button type="primary">重启</a-button>
                </a-popconfirm>
                <m-back @click="operModal=false;">关闭</m-back>
            </div>
        </a-page-header>
	</a-modal>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
			list:[],
			host:{},
			timeRefresh:false,
			timer:null,
			jarList:[],
			isLoadJarList:false,
			operModal:false,
			operHost:{},
			operJar:{},
			operParam:{},
		};
	},
	mounted(){
		this.loadHostList();
	},
	methods:{
		toTimeRefresh:function(){
			if(this.timeRefresh){
				this.loadHostList(()=>{
					if(this.timer) return;
					this.timer=setTimeout(()=>{
						this.timer=null;
						this.toTimeRefresh();
					},10000);
				});
			}
		},
		loadHostList:function(fn){
			this.requestData("action/manage/hostInfo/toList",
				{},
				function(json){
					if(json.code==0){
						this.list=json.list;
						this.host=json.host;
					}
					if(fn) fn();
				}.bind(this)
			);
		},
		loadJarList:function(visible){
			if(visible){
				this.isLoadJarList=true;
				this.requestData("action/manage/fileInfo/getBusiFile",
					{businessOid:'1',fileType:'updateJar'},
					function(json){
						if(json.code==0){
							this.jarList=json.list;
						}
						this.isLoadJarList=false;
					}.bind(this)
				);
			}
		},
		toOperHost:function(host,jar){
            this.operHost=host;
            this.operParam.xms=parseInt(host.memTotal/32);
            this.operParam.xmx=parseInt(host.memTotal/4);
            this.operJar=jar||{oid:''};
            this.operModal=true;
		},
		doOperHost:function(){
		    var param="";
		    if(this.operParam.xms) param+=" -Xms"+this.operParam.xms+"m";
		    if(this.operParam.xmx) param+=" -Xmx"+this.operParam.xmx+"m";
            this.requestData("action/manage/hostInfo/operHost",
                {ipport:this.operHost.ipport,method:'reboot',fileOid:this.operJar.oid,param:param},
                function(json){
                    if(json.code==0){
                        this.remind().success(json.msg);
                        this.operModal=false;
                    }else{
                        this.remind().error(json.msg);
                    }
                }.bind(this)
            );
		},
		stopHost:function(ipport){
			this.$confirm({
				title: '停止',
				content: '确定要停止'+ipport+'吗?',
				onOk: function(){
					this.requestData("action/manage/hostInfo/operHost",{ipport:ipport,method:'stop'},function(json){
						if(json.code==0){
							this.remind().success(json.msg);
						}else{
							this.remind().error(json.msg);
						}
					}.bind(this));
				}.bind(this)
			});
		},
		rebootHost:function(ipport){
			this.$confirm({
				title: '重启',
				content: '确定要重启'+ipport+'吗?',
				onOk: function(){
					this.requestData("action/manage/hostInfo/rebootHost",{ipport:ipport},function(json){
						if(json.code==0){
							this.remind().success(json.msg);
						}else{
							this.remind().error(json.msg);
						}
					}.bind(this));
				}.bind(this)
			});
		},
		updateHost:function(ipport,fileOid){
			this.$confirm({
				title: '重启升级',
				content: '确定要重启升级'+ipport+'吗?',
				onOk: function(){
					this.requestData("action/manage/hostInfo/updateHost",{ipport:ipport,fileOid:fileOid},function(json){
						if(json.code==0){
							this.remind().success(json.msg);
						}else{
							this.remind().error(json.msg);
						}
					}.bind(this));
				}.bind(this)
			});
		},
		viewCache:function(host){
			this.openPage('page/base/host/viewCache.js',
				{host:host},
				function(){},
				1200
			);
		}
	}
}